﻿/********************************************************************************************
 * 文件名称:	MovieInfo.cs
 * 设计人员:	严(yanxianghui@gmail.com)
 * 设计时间:	2009-03-16
 * 功能描述:	影片
 * 注意事项:	
 * 版权所有:	Copyright (c) 2009, Fujian SIRC
 * 修改记录: 	修改时间		人员		修改备注
 *				    ----------		------		-------------------------------------------------
 *
 ********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using Shanfree.Framework.Utility;
using SIRC.Framework.Net;
using System.Xml.Serialization;

namespace Shanfree.SharpMovie.Model
{
    /// <summary>
    /// 操作Movie实体时抛出的错误
    /// </summary>
    public class MovieException : Exception
    {
        public string Information { get; set; }
        public MovieException(string message)
            : base(message)
        {
            this.Information = message;
        }
    }

    /// <summary>
    /// 影片
    /// </summary>
    [Persistence(IsPrimaryKey = false, ColumnName = "Movie")]
    [Validate]
    [Serializable]
    public class MovieInfo : IConvert<MovieInfo>
    {

        string _id = string.Empty;
        /// <summary>
        /// 主键
        /// </summary>
        [Persistence(IsPrimaryKey = true, ColumnName = "ID")]
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string ID
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }

        string _IMDB_ID = string.Empty;
        /// <summary>
        /// IMDB编号
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "IMDB_ID")]
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string IMDB_ID
        {
            get
            {
                return _IMDB_ID;
            }
            set
            {
                _IMDB_ID = value;
            }
        }

        string _originalName = string.Empty;
        /// <summary>
        /// 原名
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "OriginalName")]
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string OriginalName
        {
            get
            {
                return _originalName;
            }
            set
            {
                _originalName = value;
            }
        }

        string _englishName = string.Empty;
        /// <summary>
        /// 英文名
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "EnglishName")]
        public string EnglishName
        {
            get
            {
                return _englishName;
            }
            set
            {
                _englishName = value;
            }
        }

        string _chineseName = string.Empty;
        /// <summary>
        /// 中文译名
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "ChineseName")]
        public string ChineseName
        {
            get
            {
                return _chineseName;
            }
            set
            {
                _chineseName = value;
            }
        }

        string _hongkongName = string.Empty;
        /// <summary>
        /// 港台译名
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "HongkongName")]
        public string HongkongName
        {
            get
            {
                return _hongkongName;
            }
            set
            {
                _hongkongName = value;
            }
        }

        string _postLink = string.Empty;
        /// <summary>
        /// 海报链接
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "PostLink")]
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string PostLink
        {
            get
            {
                return _postLink;
            }
            set
            {
                _postLink = value;
            }
        }

        string _produceYear = string.Empty;
        /// <summary>
        /// 出品年份
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "ProduceYear")]
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string ProduceYear
        {
            get
            {
                return _produceYear;
            }
            set
            {
                _produceYear = value;
            }
        }

        string _nationListString = string.Empty;
        /// <summary>
        /// 国家列表字串
        /// </summary>
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string NationListString
        {
            get
            {
                return _nationListString;
            }
            set
            {
                _nationListString = value;
            }
        }

        [NonSerialized]
        IList<NationInfo> _nationList = new List<NationInfo>();
        /// <summary>
        /// 拍摄国家
        /// </summary>
        [XmlIgnore]
        public IList<NationInfo> NationList
        {
            get
            {
                return _nationList;
            }
            set
            {
                _nationList = value;
            }
        }

        string _director = string.Empty;
        /// <summary>
        /// 导演
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "Director")]
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string Director
        {
            get
            {
                return _director;
            }
            set
            {
                _director = value;
            }
        }

        string _leadingRule = string.Empty;
        /// <summary>
        /// 主演
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "LeadingRule")]
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string LeadingRule
        {
            get
            {
                return _leadingRule;
            }
            set
            {
                _leadingRule = value;
            }
        }

        string _introduce = string.Empty;
        /// <summary>
        /// 简介
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "Introduce")]
        public string Introduce
        {
            get
            {
                return _introduce;
            }
            set
            {
                _introduce = value;
            }
        }

        string _awards = string.Empty;
        /// <summary>
        /// 奖项
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "Awards")]
        public string Awards
        {
            get
            {
                return _awards;
            }
            set
            {
                _awards = value;
            }
        }

        [NonSerialized]
        IList<DownloadLinkInfo> _downList = new List<DownloadLinkInfo>();
        /// <summary>
        /// 网盘链接
        /// </summary>
        [XmlIgnore]
        public IList<DownloadLinkInfo> DownloadLinkList
        {
            get
            {
                return _downList;
            }
            set
            {
                _downList = value;
            }
        }

        string _downloadLinkListString = string.Empty;
        /// <summary>
        /// 下载列表字串
        /// </summary>
        [Validate(Type = ValidateType.IsNullOrEmpty)]
        public string DownloadLinkListString
        {
            get
            {
                return _downloadLinkListString;
            }
            set
            {
                _downloadLinkListString = value;
            }
        }


        string _userID = string.Empty;
        /// <summary>
        /// 上传用户主键
        /// </summary>
        [Persistence(IsPrimaryKey = false, ColumnName = "UserID")]
        public string UserID
        {
            get
            {
                return _userID;
            }
            set
            {
                _userID = value;
            }
        }


        #region IConvert<MovieInfo> 成员
        /// <summary>
        /// 
        /// </summary>
        /// <param name="customerString">系統常量</param>
        /// <returns></returns>
        public bool Convert(string customerString)
        {
            //http://www.imdb.com/title/tt0371724/
            string imdbNo = this.IMDB_ID;
            int start = imdbNo.IndexOf("/");
            int imStart = imdbNo.IndexOf("tt", start);
            if (imStart > 0)
            {
                int imEnd = imdbNo.IndexOf("/", imStart);
                if (imEnd > -1)
                {
                    imdbNo = imdbNo.Substring(imStart, imEnd - imStart);
                }
                else
                {
                    imdbNo = imdbNo.Substring(imStart);
                }
                this.IMDB_ID = imdbNo;
            }

            string oriName = this.OriginalName;
            if (oriName.IndexOf("(") > -1)
            {
                oriName = oriName.Remove(oriName.IndexOf("("));
            }
            this.OriginalName = oriName;
            this.EnglishName = oriName;

            string introduce = this.Introduce;
            int intStart = introduce.IndexOf(":");
            int intEnd = introduce.IndexOf("|");
            if (intStart > 0 && intEnd > 0)
            {
                this.Introduce = introduce.Substring(intStart + 1, intEnd - intStart - 1);

            }

            string awards = this.Awards;
            if (awards.EndsWith("more"))
            {
                this.Awards = awards.Remove(awards.Length - 4);
            }
            return true;
        }

        #endregion
    }
}
